﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;

namespace Client
{
    public static class Client
    {
        public static HttpWebResponse GetResponse(string url, string requestType, string contentType, int timeout, byte[] data)
        {
            HttpWebResponse res = null;

            try
            {
                WebRequest request = HttpWebRequest.Create(url);

                request.Timeout       = timeout;
                request.Method        = requestType;

                if (data != null)
                {
                    request.ContentType   = contentType;
                    request.ContentLength = data.Length;

                    Stream stream = request.GetRequestStream();
                
                    stream.Write(data, 0, data.Length);
                    stream.Close();
                }

                res = (HttpWebResponse)request.GetResponse();
            }
            catch { }

            return res;
        }

        public static HttpWebResponse GetResponse(string url, string requestType, string contentType, byte[] data)
        {
            return GetResponse(url, requestType, contentType, Defaults.TIMEOUT, data);
        }        
    }    
}
